package com.codersatwork.email;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @author Saurabh Agrawal
 * @crated Feb 14, 2010
 */

public class MailSender extends JavaMailSenderImpl implements InitializingBean {

    private Boolean smtpSSLEnabled;


    /**
     * We will check the configuration, and populate the propertes in the JavaMailSenderImpl bean.
     */
    public void afterPropertiesSet() throws Exception {
        Properties properties = new Properties();
        if (smtpSSLEnabled) {
            properties.setProperty("mail.smtp.auth", "true");
            properties.setProperty("mail.smtp.starttls.enable", "true");
            properties.setProperty("mail.smtp.timeout", "8500");
            setJavaMailProperties(properties);
        }
    }


    public void setSmtpSSLEnabled(final Boolean smtpSSLEnabled) {
        this.smtpSSLEnabled = smtpSSLEnabled;
    }


}